#' Entropy
entropy <- function(x) {
  stopifnot(is.atomic(x))
  x <- table(x, useNA = "ifany")/length(x)
  -sum(x*log2(x))
}

#' majority vote
compute_mv <- function(x) {
  stopifnot(is.atomic(x))
  
  t <- rev(sort(table(x, useNA = "always")))
  if (length(t) == 1L) {
    return(names(t))
  } else if (t[1] == t[2]) {
    return(sample(names(t)[1:2], 1))
  } else {
    return(names(t)[1])
  }
}
